using FarPoint.Win.Spread;
using GrapeCity.Spreadsheet;

namespace Spread.Sparkline.Features
{
    public partial class VariSparkline : Spread.Common.Features.Sample.BaseSampleControl
    {
        public VariSparkline()
        {
            InitializeComponent();
            Name = "Vari";

            InitSpread();
        }

        #region Private methods
        private void InitSpread()
        {
            IWorksheet worksheet = fpSpread1.ActiveSheet.AsWorksheet();
            var table = worksheet.Tables.Add("A1:E13", YesNoGuess.Yes, FarPoint.Win.Spread.TableStyle.TableStyleMedium4, "Table1");
            table.ShowAutoFilter = false;
            worksheet.SetValue(0, 0, new object[,]
            {
                { "Sales", "Budget", "Actual", "Variance", "Variance %" },
                { "Jan", 305554, 336431, null, null },
                { "Feb", 280311, 370582, null, null },
                { "Mar", 309347, 322689, null, null },
                { "Apr", 502688, 386790, null, null },
                { "May", 351267, 363122, null, null },
                { "Jun", 351922, 314589, null, null },
                { "Jul", 364770, 342515, null, null },
                { "Aug", 373980, 317154, null, null },
                { "Sep", 397717, 360083, null, null },
                { "Oct", 275849, 370909, null, null },
                { "Nov", 426031, 376791, null, null },
                { "Dec", 267710, 398198, null, null }
            });
            for (int i = 2; i < 14; i++)
            {
                worksheet.Cells[$"D{i}"].Formula = "(C" + i + "-B" + i + ")";
                worksheet.Cells[$"E{i}"].Formula2 = "VARISPARKLINE(ROUND((D" + i + ")/(B" + i + "),2),0,-1,1,,0.2,TRUE)";
            }

            worksheet.Cells["B2:D13"].HorizontalAlignment = HorizontalAlignment.Left;
            worksheet.Cells["B2:D13"].NumberFormat = "$#,000;$-#,000";

            worksheet.Cells["E2:E13"].HorizontalAlignment = HorizontalAlignment.Left;
            worksheet.Cells["E2:E13"].NumberFormat = "0%";

            worksheet.Columns["B:D"].ColumnWidth = 120;
            worksheet.Columns["E"].ColumnWidth = 200;
        }
        #endregion
    }
}


//
//VariSparkline.Designer.cs
//



namespace Spread.Sparkline.Features
{
    partial class VariSparkline
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(VariSparkline));
            this.fpSpread1 = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, ((object)(resources.GetObject("pnlMain.Controls"))));
            this.fpSpread1_Sheet1 = this.fpSpread1.GetSheet(0);
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).BeginInit();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this.fpSpread1);
            // 
            // pnlControls
            // 
            this.pnlControls.Size = new System.Drawing.Size(210, 599);
            // 
            // fpSpread1
            // 
            this.fpSpread1.AccessibleDescription = "Book1, Sheet1, Row 0, Column 0";
            this.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fpSpread1.Font = new System.Drawing.Font("Calibri", 11F);
            this.fpSpread1.Location = new System.Drawing.Point(0, 0);
            this.fpSpread1.Name = "fpSpread1";
            this.fpSpread1.Size = new System.Drawing.Size(636, 599);
            this.fpSpread1.TabIndex = 3;
            // 
            // VariSparkline
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "VariSparkline";
            this.pnlMain.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion
        private FarPoint.Win.Spread.FpSpread fpSpread1;
        private FarPoint.Win.Spread.SheetView fpSpread1_Sheet1;
    }
}
